package com.xjk.web.controller.education;

import com.xjk.common.annotation.Log;
import com.xjk.common.core.controller.BaseController;
import com.xjk.common.core.domain.AjaxResult;
import com.xjk.common.core.page.TableDataInfo;
import com.xjk.common.enums.BusinessType;
import com.xjk.common.utils.poi.ExcelUtil;
import com.xjk.education.domain.EduProgrammes;
import com.xjk.education.service.IEduProgrammesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 课程信息Controller
 * 
 * @author xjk
 * @date 2024-07-20
 */
@RestController
@RequestMapping("/education/programmes")
public class EduProgrammesController extends BaseController
{
    @Autowired
    private IEduProgrammesService eduProgrammesService;

    /**
     * 查询课程信息列表
     */
    @PreAuthorize("@ss.hasPermi('education:programmes:list')")
    @GetMapping("/list")
    public TableDataInfo list(EduProgrammes eduProgrammes)
    {
        startPage();
        List<EduProgrammes> list = eduProgrammesService.selectEduProgrammesList(eduProgrammes);
        return getDataTable(list);
    }

    /**
     * 导出课程信息列表
     */
    @PreAuthorize("@ss.hasPermi('education:programmes:export')")
    @Log(title = "课程信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EduProgrammes eduProgrammes)
    {
        List<EduProgrammes> list = eduProgrammesService.selectEduProgrammesList(eduProgrammes);
        ExcelUtil<EduProgrammes> util = new ExcelUtil<EduProgrammes>(EduProgrammes.class);
        util.exportExcel(response, list, "课程信息数据");
    }

    /**
     * 获取课程信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('education:programmes:query')")
    @GetMapping(value = "/{programmesId}")
    public AjaxResult getInfo(@PathVariable("programmesId") Long programmesId)
    {
        return success(eduProgrammesService.selectEduProgrammesByProgrammesId(programmesId));
    }

    /**
     * 新增课程信息
     */
    @PreAuthorize("@ss.hasPermi('education:programmes:add')")
    @Log(title = "课程信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EduProgrammes eduProgrammes)
    {
        return toAjax(eduProgrammesService.insertEduProgrammes(eduProgrammes));
    }

    /**
     * 修改课程信息
     */
    @PreAuthorize("@ss.hasPermi('education:programmes:edit')")
    @Log(title = "课程信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EduProgrammes eduProgrammes)
    {
        return toAjax(eduProgrammesService.updateEduProgrammes(eduProgrammes));
    }

    /**
     * 删除课程信息
     */
    @PreAuthorize("@ss.hasPermi('education:programmes:remove')")
    @Log(title = "课程信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{programmesIds}")
    public AjaxResult remove(@PathVariable Long[] programmesIds)
    {
        return toAjax(eduProgrammesService.deleteEduProgrammesByProgrammesIds(programmesIds));
    }
}
